package io;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public abstract class CSVReader {

	protected ArrayList<ArrayList<String>> readFile(String fileName) {

		BufferedReader CSVFile = null;
		
		try {
			CSVFile = new BufferedReader(new FileReader(fileName));
			
		} catch (FileNotFoundException e) {
			System.out.println("File not found!");
			
		}

		ArrayList<ArrayList<String>> courseTable = new ArrayList<ArrayList<String>>();

		String dataRow = "";
		try {
			// The while checks to see if the data is null. If
			// it is, we've hit the end of the file. If not,
			// process the data.
			dataRow = CSVFile.readLine();
			
			while (dataRow != null) { // Read next line of data.
				String[] dataArray = dataRow.split(",");
				
				ArrayList<String> csvEntry = new ArrayList<String>();
				for(String data : dataArray) {
					csvEntry.add(data);
				}

				courseTable.add(csvEntry);
				
				dataRow = CSVFile.readLine();
			}

			// Close the file once all data has been read.
			CSVFile.close();
			
		} catch (IOException e) {
			System.out.println("File read error!");
			
		}

		return (courseTable);
	}
}
